package com.jxtc.enterprise.admin.controller;


import com.alibaba.fastjson.JSONObject;
import com.jxtc.enterprise.common.constants.PrinterTypeEnum;
import com.jxtc.enterprise.common.mapper.StoreMapper;
import com.jxtc.enterprise.common.utils.Result;
import com.jxtc.enterprise.common.utils.ResultGenerator;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * TODO: 是否应该考虑放到 common.controller 下呢
 */
@RestController
@RequestMapping("/jxtc/enterprise/systemSettings")
@Slf4j
public class SystemSettingController {

    HashMap<String,Object> systemSettings = new HashMap<>();


    @PostConstruct
    public void initData() {
        // 数据库中 print_label_type 列的值 1：贴纸, 2：外卖小票
        systemSettings.put("printerTypes", Arrays.asList(PrinterTypeEnum.TIE_ZHI_PRINTER.getPrinterTypeName(), PrinterTypeEnum.XIAO_PIAO_PRINTER.getPrinterTypeName()));
    }

    @Autowired
    private StoreMapper storeMapper;

    /**
     * 查询系统配置
     * @param requestBody
     * @return
     */
    @Operation(summary = "14.1 新增店铺", tags = {"14. Admin 店铺管理"}, operationId = "14.1")
    @PostMapping("/querySystemSetting")
    public Result<?> querySystemSetting(@RequestBody() JSONObject requestBody){

        // todo 后期新增 系统配置表，将配置存入表中
        String argName = requestBody.getString("argName");
        List<String> printerTypes = (List<String>)systemSettings.get(argName);

        return ResultGenerator.genSuccessResult(printerTypes);
    }
}
